package Progra1;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author manuel
 */
public class servletCaso2 extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        try {
            Caso2BD manejoBD = new Caso2BD();
            manejoBD.conectarBD();
            HttpSession session = request.getSession();
            int resultado = 0;
            if (request.getParameter("botonObtenerId") != null) {
                int idObtenido = manejoBD.caso2ObtenerId();
                session.setAttribute("idObtenido", idObtenido);
                resultado=1;
            } else if (request.getParameter("botonIngresar1") != null) {
                resultado = manejoBD.caso2IngresarProblema(Integer.parseInt(request.getParameter("id")), request.getParameter("color1"));
            } else if (request.getParameter("botonIngresar2") != null) {
                resultado = manejoBD.caso2IngresarSolucion(request.getParameter("color2"));
            }
                response.setContentType("text/html");
                response.sendRedirect("Caso2.jsp?estadoIngreso="+resultado);
                request.getRequestDispatcher("/Caso2.jsp").forward(request, response);

        } catch (Throwable exc) {
        }
    }
}
